package LeetCode;

import java.util.Comparator;
import java.util.PriorityQueue;

public class Num1046 {
    public int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> queue=new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        for (int stone:stones){
            queue.offer(stone);
        }
        while (queue.size()>1){
            int a=queue.poll();
            int b=queue.poll();
            if(a>b){
                queue.offer(a-b);
            }
        }
        return queue.isEmpty()?0:queue.poll();

    }
}
